package com.heima.wemedia.controller.v1;

import com.heima.common.dtos.PageResponseResult;
import com.heima.common.dtos.ResponseResult;
import com.heima.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.dtos.WmMaterialDto;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.pojos.WmMaterial;
import com.heima.wemedia.service.WmMaterialService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/v1")
public class WmMaterialController {

    @Resource
    private WmMaterialService wmMaterialService;
    /**
     * 上传图片
     */
    @PostMapping("/material/upload_picture")
    public ResponseResult<WmMaterial> uploadPicture(@RequestParam("multipartFile") MultipartFile multipartFile) {
        return this.wmMaterialService.uploadPicture(multipartFile);
    }
    /**
     * 素材列表查询
     */
    @PostMapping("/material/list")
    public PageResponseResult<List<WmMaterial>> findList(@RequestBody WmMaterialDto dto){
        return this.wmMaterialService.findList(dto);
    }

    /**
     * 删除图片
     * @param id
     * @return
     */
    @GetMapping("/material/del_picture/{id}")
    public ResponseResult<AppHttpCodeEnum> delPicture(@PathVariable("id") Long id){
        return this.wmMaterialService.delPicture(id);
    }

    /**
     * 收藏
     * @param id
     * @return
     */
    @GetMapping("/material/cancel_collect/{id}")
    public ResponseResult<AppHttpCodeEnum> collect(@PathVariable("id") Long id){
        return this.wmMaterialService.collect(id);
    }
    /**
     *
     */
    @GetMapping("/material/collect/{id}")
    public ResponseResult<AppHttpCodeEnum> cancelCollect(@PathVariable("id") Long id){
        return this.wmMaterialService.cancelCollect(id);
    }

    /**
     * 根据id查询新闻详情
     * @param id
     * @return
     */
    @GetMapping("/news/one/{id}")
    public ResponseResult findOne(@PathVariable("id") Long id) {
        return this.wmMaterialService.findOne(id);
    }

    /**
     * 删除新闻
     * @param id
     * @return
     */
    @GetMapping("/news/del_news/{id}")
    public ResponseResult delNews(@PathVariable("id") Long id) {
        return this.wmMaterialService.delNews(id);
    }

    /**
     * 文章上下架
     * @param dto
     * @return
     */
    @PostMapping("/news/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto dto) {
        return this.wmMaterialService.downOrUp(dto);
    }


}
